home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 5 / Gekikoh Dennoh Club Vol. 5 (Japan).7z / Gekikoh Dennoh Club Vol. 5 (Japan) (Track 01).bin / internet / webx / webxp040.lzh / Source / Config.c < prev    next >
C/C++ Source or Header  |  1998-09-27  |  5KB  |  202 lines

  1. /* Config.c    WebXpression.cnf ô╟é▌ì₧é▌ */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <sys/xglob.h>
  7.  
  8.  
  9. /* WebCache.cnf é┼É▌ÆΦé╖éΘÆlüòé╗é╠Åëè·Æl */
  10. unsigned char hold_online = 1;
  11. unsigned char image_compress = 1;
  12. unsigned char image_quality = 0;
  13. unsigned char key_repeat_1st = 30;
  14. unsigned char key_repeat_2nd = 5;
  15. unsigned char color_mode = 0;
  16. unsigned char refresh_rate = 4;
  17. unsigned short cache_image = 4;
  18. unsigned short webcache_save = 4;
  19. unsigned short history_max = 32;
  20. unsigned short config_color[7];
  21. int line_table_size = 4096;
  22. int link_table_size = 1024;
  23. int link_table_buffer_size = 32768;
  24. int image_table_size = 1024;
  25. int anchor_table_size = 1024;
  26. char text_editor[64];
  27.  
  28.  
  29. extern struct _psp *mypsp;
  30.  
  31. typedef struct {
  32.     char *var_name;
  33.     unsigned char *var_ptr;
  34. } VAR_CHAR;
  35.  
  36. VAR_CHAR var_char[]=
  37. {
  38.     "hold-online", &hold_online,
  39.     "image-compress", &image_compress,
  40.     "image-quality", &image_quality,
  41.     "key-repeat-1st", &key_repeat_1st,
  42.     "key-repeat-2nd", &key_repeat_2nd,
  43.     "color-mode", &color_mode,
  44.     "refresh-rate", &refresh_rate,
  45.     NULL, NULL
  46. };
  47.  
  48. typedef struct {
  49.     char *var_name;
  50.     unsigned short *var_ptr;
  51. } VAR_SHORT;
  52.  
  53. VAR_SHORT var_short[]=
  54. {
  55.     "cache-image", &cache_image,
  56.     "webcache-save", &webcache_save,
  57.     "history-max", &history_max,
  58.     NULL, NULL
  59. };
  60.  
  61. typedef struct {
  62.     char *var_name;
  63.     unsigned short *var_ptr;
  64. } VAR_RGB;
  65.  
  66. VAR_RGB var_rgb[]=
  67. {
  68.     "color-back", &config_color[0],
  69.     "color-str", &config_color[1],
  70.     "color-clear", &config_color[2],    /* â_â~ü[ */
  71.     "color-link", &config_color[3],
  72.     "color-fixed-back", &config_color[4],
  73.     "color-fixed-highlight", &config_color[5],
  74.     "color-fixed-str", &config_color[6],
  75.     NULL, NULL
  76. };
  77.  
  78. typedef struct {
  79.     char *var_name;
  80.     unsigned int *var_ptr;
  81. } VAR_INT;
  82.  
  83. VAR_INT var_int[]=
  84. {
  85.     "line-table-size", &line_table_size,
  86.     "link-table-size", &link_table_size,
  87.     "link-table-buffer-size", &link_table_buffer_size,
  88.     "image-table-size", &image_table_size,
  89.     "anchor-table-size", &anchor_table_size,
  90.     NULL, NULL
  91. };
  92.  
  93.  
  94. typedef struct {
  95.     char *var_name;
  96.     unsigned char *var_ptr;
  97. } VAR_STR;
  98.  
  99. VAR_STR var_str[]=
  100. {
  101.     "text-editor", text_editor,
  102.     NULL, NULL
  103. };
  104.  
  105.  
  106.  
  107. /* ïNô«Ä₧é╔éPë±é╛é»î─é╬éΩéΘ */
  108. int InitConfig (char *fname)
  109. {
  110.     FILE *fp;
  111.     short h;
  112.     char temp_str[256];
  113.  
  114.     strcpy (temp_str, mypsp->exe_path);
  115.     _addlastsep (temp_str);
  116.     strcat (temp_str, fname);
  117.     /* âJâîâôâgâfâBâîâNâgâèé≡îƒì⌡ */
  118.     if ((fp = fopen (fname, "r")) == NULL) {
  119.         /* WebXpression.x é╠éáéΘâfâBâîâNâgâèé≡îƒì⌡ */
  120.         if ((fp = fopen (temp_str, "r")) == NULL) {
  121.             printf ("âRâôâtâBâOâtâ@âCâïé¬ô╟é▀é▄é╣é±\n");
  122.             return (-1);
  123.         }
  124.     }
  125.     while (fscanf (fp, "%s", temp_str) != EOF) {
  126.         char nl = 0;    /* Äƒìsé╓ìsé¡âtâëâO */
  127.         if (ferror (fp) || feof (fp))
  128.             break;
  129.  
  130.         h = 0;
  131.         do {        /* char î^ò╧Éöô╟é▌ì₧é▌ */
  132.             if (!strcmp (temp_str, var_char[h].var_name)) {
  133.                 unsigned int t;
  134.                 fscanf (fp, "%d", &t);
  135.                 *var_char[h].var_ptr = (unsigned char) t;
  136.                 fgets (temp_str, 256, fp);    /* ê╚ë║ëⁿìsé▄é┼ô╟é▌Ä╠é─éΘ */
  137.                 nl = !0;
  138.                 break;
  139.             }
  140.         } while (var_char[++h].var_name != NULL);
  141.         if (nl)
  142.             continue;
  143.  
  144.         h = 0;
  145.         do {        /* short î^ò╧Éöô╟é▌ì₧é▌ */
  146.             if (!strcmp (temp_str, var_short[h].var_name)) {
  147.                 fscanf (fp, "%hd", var_short[h].var_ptr);
  148.                 fgets (temp_str, 256, fp);    /* ê╚ë║ëⁿìsé▄é┼ô╟é▌Ä╠é─éΘ */
  149.                 nl = !0;
  150.                 break;
  151.             }
  152.         } while (var_short[++h].var_name != NULL);
  153.         if (nl)
  154.             continue;
  155.  
  156.         h = 0;
  157.         do {        /* short î^ò╧Éöüir,g,b é┼ÄwÆΦüjô╟é▌ì₧é▌ */
  158.             if (!strcmp (temp_str, var_rgb[h].var_name)) {
  159.                 unsigned int r, g, b;
  160.                 fscanf (fp, "%d,%d,%d", &r, &g, &b);
  161.                 *(var_rgb[h].var_ptr) = (unsigned short) ((g << 11) | (r << 6) | (b << 1));
  162.                 fgets (temp_str, 256, fp);    /* ê╚ë║ëⁿìsé▄é┼ô╟é▌Ä╠é─éΘ */
  163.                 nl = !0;
  164.                 break;
  165.             }
  166.         } while (var_rgb[++h].var_name != NULL);
  167.         if (nl)
  168.             continue;
  169.  
  170.         h = 0;
  171.         do {        /* int î^ò╧Éöô╟é▌ì₧é▌ */
  172.             if (!strcmp (temp_str, var_int[h].var_name)) {
  173.                 fscanf (fp, "%d", var_int[h].var_ptr);
  174.                 fgets (temp_str, 256, fp);    /* ê╚ë║ëⁿìsé▄é┼ô╟é▌Ä╠é─éΘ */
  175.                 nl = !0;
  176.                 break;
  177.             }
  178.         } while (var_int[++h].var_name != NULL);
  179.         if (nl)
  180.             continue;
  181.  
  182.         h = 0;
  183.         do {        /* char[] î^ò╧Éöô╟é▌ì₧é▌ */
  184.             if (!strcmp (temp_str, var_str[h].var_name)) {
  185.                 char *p = var_str[h].var_ptr;
  186.                 while (fgetc (fp) != (int) '"');
  187.                 while ((*p++ = (char) fgetc (fp)) != '"');
  188.                 *(p - 1) = '\0';
  189.                 fgets (temp_str, 256, fp);    /* ê╚ë║ëⁿìsé▄é┼ô╟é▌Ä╠é─éΘ */
  190.                 nl = !0;
  191.                 break;
  192.             }
  193.         } while (var_str[++h].var_name != NULL);
  194.         if (nl)
  195.             continue;
  196.  
  197.         fgets (temp_str, 256, fp);    /* ê╚ë║ëⁿìsé▄é┼ô╟é▌Ä╠é─éΘ */
  198.     }
  199.  
  200.     return (0);
  201. }
  202.